fix: crash when self user is mentioned multiple times in last message [WPB-15157] #3192
+85
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Submission Checklist for internal contributors
The PR Title
SQPIT-764
The PR Description
What's new in this PR?
Issues
When self user receives a message in which he/she is mentioned more than once, the app crashes as long as this message is the last one for the given conversation:
java.lang.IllegalArgumentException: Key "[email protected]" was already used
Causes (Optional)
When making a query, we left-join
MessageMention
with self_user_id or null if there are no mentions in last message for self user, however, this table has primary key consisting of not onlymessage_id
andconversation_id
which means that there can be more than one mention in a given last message, moreover - self user can be mentioned more than once and that's what happens - self user has two mentions in last conversation message and then left-join creates two rows for the given conversation with both mentions.Solutions
Count self user mentions and group results by
conversation_id
so that we're sure that there will only be a single row for each conversation.When I was analysing and making tests of different approaches to find optimal one back then (#3098) I also noticed that having
group by conversation_id
doesn't affect the execution time, so it should be safe to use that.PR Post Submission Checklist for internal contributors (Optional)
PR Post Merge Checklist for internal contributors
References
feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764
.